<?php header("Content-Type:text/html;charset=utf-8"); ?>
<html>
<head>
		<style>
		#candidated_list{
			margin-left: auto;
			margin-right: auto;
			border: solid 1px black;
			background-color: #c9e378;
		}
		.record_div{
			border: solid 1px black;
		}
		</style>
</head>
<body>
<?php
/**
	ABSTRACT

	File name:			dbCon_config.html
	Version:			1.0
	Initial author:		Haitao Huang
	Create date:		4th Apr 2016
	Lastest edit:		28th Apr 2016
	Description:		connect the database and return the query fetch from the front-end form,
									and display the list for candidated url link.
**/
	include "dbmng/dbconn.php";
	include "console_command.php";

// -----------------------------------------------------------------------------
	function _update_sqlStatClauseSet(){
		echo "(key-value pairs from form:)<br/>";
		foreach($_GET as $key=>$value){
		 	if($value != NULL){
		 		if($key == 'phy'){
				 	global $sqlStatClause_set;
				 	$sqlStatClause_set[$key . '_clause'] = $key . '_name_la = ' . "\"" . $value . "\"";
				 	echo '{stat clause: ' . $sqlStatClause_set[$key . '_clause'] . '}';
			 	}elseif ($key != 'stext'){
			 	 	$sqlStatClause_set[$key . '_clause'] = ' AND ' . $key . '_name_la = ' . "\"" . $value . "\"";
				 	echo '{stat clause: ' . $sqlStatClause_set[$key . '_clause'] . '}';
			 	}
		 	}
		}
	}
// -----------------------------------------------------------------------------
$sqlStatClause_set = array('phy_clause' => NULL,
											 'cla_clause' => NULL,
											 'ord_clause' => NULL,
											 'fam_clause' => NULL,
											 'gen_clause' => NULL,
											 'stext' => NULL
											);
	_console_OP_getMethod_value(); // FOR CONSOLE.
	_update_sqlStatClauseSet();

	function _getValue_process(){
		return;
	}

		$mydbconn = dbConn();

		/**---------------**/
		$sqlStat_whereClause = NULL;
		$sqlStat_whereClause = strval($sqlStat_whereClause);
		foreach ($sqlStatClause_set as $key => $value) {
			if ($value != NULL) {
				$sqlStat_whereClause = $sqlStat_whereClause . $value;
			}
		}
		echo '{$sqlStat_whereClause: ' .$sqlStat_whereClause . '}';
		/**---------------**/

		$sqlStat = "SELECT * FROM local_plants WHERE " .	// "select" main statement
									$sqlStat_whereClause .	// "where" clause
									" LIMIT 0, 3;";	// "limit" clause

		_console_OP_sqlStatment($sqlStat); // cosole output

		$sqlResult = $mydbconn->query($sqlStat);
		if($sqlResult){
			$recordtNum = 1;
			echo "<div id = \"candidated_list\">";
			while ($sqlcont = $sqlResult->fetch_assoc()){
				/** statment for test
				$content = "No.:" . $sqlcont["spe_no"] . "->" .
									 "species:" . $sqlcont["spe_name_la"] . "->" .
				           "phylum:" . $sqlcont["phy_name_la"] . "->" .
									 "class:" . $sqlcont["cla_name_la"] . "->" .
									 "order:" . $sqlcont["ord_name_la"] . "->" .
									 "family:" . $sqlcont["fam_name_la"] . "->" .
									 "genus:" . $sqlcont["gen_name_la"];
				echo "<p>" . $content . "</p>";
				**/
				if($recordtNum % 2 == 0){
					echo "<div class=\"record_div\" id =\"list_record_" . $recordtNum . "\" style=\"background-color:#c2f4de\">";
				}else{
					echo "<div class=\"record_div\" id =\"list_record_" . $recordtNum . "\" style=\"background-color:#ddfbcf\">";
				}
				echo "<p>record " . $recordtNum . "</p>";
				$urlLink =  "<a href=\"plant_speice.php?" . "spe_no=" . $sqlcont["spe_no"] . "\">" . $sqlcont["spe_name_la"] ."</a>";
				echo $urlLink;
				echo "</div>";
				$recordtNum++;
			}
			echo "</div>";
			_console_OP_queryRecordNum($sqlResult);
			//echo "<p>". $sqlResult->num_rows ." row result have turned!</p>";
		}else{
			echo "SQL query fail!";
		}


?>
</body>
</html>
